$(function () {

    //新增
    $("#btn_save_new_cust").click(function () {

        var form = window.form_new_cust;
        var custName = form.custName.value;
        var custCode = form.custCode.value;
        var addr = form.addr.value;
        var state = form.state.value;
        var areaId = form.areaId.value;

        var lgsCust = {custName: custName,custCode: custCode, addr: addr,state: state,areaId:areaId };
        $.postJsonBody("/lgsCust/postLgsCust", lgsCust, function (re) {
            window.location.href=window.location.href;
            window.location.reload;
        })
    });


    // 编辑详情
    $('#md_edit_cust').on('show.bs.modal', function (event) {
        var _e = $(event.relatedTarget);
        var id = _e.data("cust-id");
        var modal = $(this);
        var form = window.form_edit_cust;
        $.get("/lgsCust/getLgsCust/" + id, function (re) {
            var cust = re.data.lgsCust;
            form.id.value = cust.id;
            form.custName.value = cust.custName;
            form.custCode.value = cust.custCode;
            form.addr.value = cust.addr;
            form.areaId.value = cust.areaId;
            form.state.value = cust.state;


        });
    });

    //编辑
    $("#btn_save_edit_cust").click(function () {
        var form = window.form_edit_cust;
        var id = form.id.value;
        var custName = form.custName.value;
        var custCode = form.custCode.value;
        var addr = form.addr.value;
        var state = form.state.value;
        var areaId = form.areaId.value;
        var cust = {id:id,custName: custName,custCode: custCode, addr: addr,state: state,areaId:areaId};
        $.postJsonBody("/lgsCust/update" , cust, function (re) {

            window.location.href=window.location.href;
            window.location.reload;
        })
    });


})